<?php

namespace app\user\controller;

use app\common\respond\HttpApi;
use app\user\logic\BarnLogic;

class BarnController
{
    /**
     * @Description 列表
     * @author: zj
     * @param HttpApi $respond
     * @time 2023/08/26 16:50:40
     * @return null
     */
    public function list(HttpApi $respond)
    {
        $param = [
            'page' => (int) request()->get('page') ?: 1,
            'page_size' => (int) request()->get('page_size') ?: 10,
            'name' => request()->get('name')
        ];
        $rule = [
            'page' => 'require|integer|>:0',
            'page_size' => 'require|integer|>:0',
            'name' => 'max:30'
        ];
        validate($rule)->check($param);

        $logic = new BarnLogic();
        $data = $logic -> getList($param);

        return $respond->success($data);
    }

    /**
     * @Description 栋详情
     * @author: zj
     * @param HttpApi $respond
     * @time 2023/08/30 10:09:43
     * @return null
     */
    public function detail(HttpApi $respond)
    {
        $param = [
            'id' => request()->get('id')
        ];
        $rule = [
            'id' => 'require|>:0'
        ];
        validate($rule)->check($param);

        $logic = new BarnLogic();
        $data = $logic->getDetail($param['id']);

        return $respond->success($data);
    }

    /**
     * @Description 下拉列表
     * @author: zj
     * @param HttpApi $respond
     * @time 2023/08/26 16:54:38
     * @return null
     */
    public function selectList(HttpApi $respond)
    {
        $param = [
            'page' => (int) request()->get('page') ?: 1,
            'page_size' => (int) request()->get('page_size') ?: 10,
            'name' => request()->get('name'),
        ];
        $rule = [
            'page' => 'require|integer|>:0',
            'page_size' => 'require|integer|>:0',
            'name' => 'max:30'
        ];
        validate($rule)->check($param);

        $logic = new BarnLogic();
        $data = $logic -> getSelectList($param);

        return $respond->success($data);
    }

    /**
     * @Description 修改栋名
     * @author: zj
     * @param HttpApi $respond
     * @time 2023/09/20 09:58:28
     * @return null
     */
    public function edit(HttpApi $respond)
    {
        $param = [
            'id' => request()->post('id'),
            'name' => request()->post('name')
        ];
        $rule = [
            'id' => 'require|>:0',
            'name' => 'require|max:30',
        ];
        validate($rule)->check($param);

        $factoryId = request()->user_info['factory_id'];

        $logic = new BarnLogic();
        $data = $logic->edit($factoryId,$param);

        return $respond->success([]);
    }

    /**
     * @Description 通过食谱id获取猪栏列表
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/26 18:14:53
     * @return \think\response\Json
     */
    public function useCookBookBarn(HttpApi $respond)
    {
        $param = [
            'page' => (int)request()->get('page') ?: 1,
            'page_size' => (int)request()->get('page_size') ?: 10,
            'feed_plan_id' => request()->get('feed_plan_id')
        ];
        $rule = [
            'page' => 'require|integer|>:0',
            'page_size' => 'require|integer|>:0',
            'feed_plan_id' => 'require|integer|>:0'
        ];
        validate($rule)->check($param);

        $logic = new BarnLogic();
        $data = $logic->useCookBookBarn($param);

        return $respond->success($data);
    }

}